package com.firexxx.study.exception;

import com.firexxx.study.util.ExceptionUtil;
import com.firexxx.study.web.response.BusinessError;
import org.springframework.util.StringUtils;


/**
 * @description: TODO
 * @throws:
 * @author: zhuangzhang2
 * @date: 2020/04/09 14:40
 */
public class BusinessException extends RuntimeException {
    /**
     * ERROR
     **/
    private BusinessError error;

    public BusinessException(BusinessError error) {
        super(error.getDesc());
        this.error = error;
    }

    public BusinessException(String message, BusinessError error) {
        super(message);
        this.error = error;

        if (!StringUtils.isEmpty(message)) {
            this.error.setDesc(message);
        }
    }

    public BusinessException(String message, Throwable cause, BusinessError error) {
        super(message, cause);
        this.error = error;
    }

    public BusinessException(Throwable cause, BusinessError error) {
        super(cause);
        this.error = error;
    }

    public String getFirstNonNullMessage() {
        return ExceptionUtil.getFirstNonNullMessage(this);
    }

    public BusinessError getError() {
        return error;
    }
}